package leecode;

import java.util.ArrayList;
import java.util.List;

/**
 * 杨辉三角
 * easy
 */
class _118 {
    static List<List<Integer>> res= new ArrayList<>();
    static List<Integer> row = null;
    static int num = 0;
    public static List<List<Integer>> generate(int numRows) {
        if (numRows < 0 || num == numRows) {
            return res;
        }
        row = new ArrayList<>();
        row.add(0, 1);
        for (int i = 1; i < num; i++) {
            List<Integer> lastRow = res.get(num - 1);
            row.add(i, lastRow.get(i -1) + lastRow.get(i));
        }
        if (num > 0) {
            row.add(num, 1);
        }
        res.add(row);
        num++;
        return generate(numRows);
    }

    public static void main(String[] args) {
        generate(5);
        System.out.println(1);
    }

    public int calPoints(String[] operations) {
        String[] res = new String[operations.length];
        //解析
        for (int i = 0; i < operations.length; i++) {
            String op = operations[i];
            switch (op) {
                case "+" : res[i] = String.valueOf(Integer.parseInt(res[i - 1]) + Integer.parseInt(res[i - 2]));
                    break;
                case "D" : res[i] = String.valueOf(Integer.parseInt(res[i - 1]) * 2);
                    break;
                case "C" : res[i] = "0"; res[i - 1] = "0";
                    break;
                default :
                    res[i] = op;
            }
        }
        //累计
        int num = 0;
        for (int i = 0; i < res.length; i++) {
            num += Integer.parseInt(res[i]);
        }
        return num;
    }
}